package com.atguigu.gmall.all.contoller;

import com.atguigu.gmall.activity.client.SeckillFeignClient;
import com.atguigu.gmall.model.activity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author: 李旭
 * @create: 2021-07-28 11:22
 **/
@Controller
public class SeckillController {

    @Autowired
    private SeckillFeignClient seckillFeignClient;

    //去秒杀的首页
    @GetMapping("/index")
    public String seckillIndex(Model model) {
        List<SeckillGoods> seckillGoodsList = seckillFeignClient.list();
        model.addAttribute("list", seckillGoodsList);
        return "seckill/index";
    }
    //去秒杀详情页面
    @GetMapping("/seckill/{skuId}.html")
    public String seckillIndex(Model model, @PathVariable Long skuId) {
        SeckillGoods seckillGoods = seckillFeignClient.findSeckillGoodsById(skuId);
        model.addAttribute("item",seckillGoods );
        return "seckill/item";
    }
    //去抢购页面
    @GetMapping("/seckill/queue.html")
    public String toQueue(Long skuId,String skuIdStr,Model model){

        model.addAttribute("skuId",skuId);
        model.addAttribute("skuIdStr",skuIdStr);
        return "seckill/queue";
    }


}
